package com.atguigu.activemq.queue_delay;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;


public class JmsConsumer {
    public static final String QUEUE_NAME="queue_Delay";
    public static final String ACTIVEMQ_URL="tcp://124.70.84.192:61616";
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory activeMQConnectionFactory=new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(QUEUE_NAME);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        System.out.println("2号消费者");
        while (true){
            TextMessage textMessage= (TextMessage)messageConsumer.receive(4000l);
            if(null!=textMessage){
                System.out.println(textMessage.getText());
            }else {
                break;
            }
        }
        messageConsumer.close();
        session.close();
        connection.close();
    }
}
